package cn.tedu.controller;

import cn.tedu.pojo.dto.WxUserinfoDTO;
import cn.tedu.pojo.entity.WxUserinfo;
import cn.tedu.pojo.vo.JsonResult;
import cn.tedu.pojo.vo.PageInfo;
import cn.tedu.pojo.vo.WxUserinfoVo;
import cn.tedu.service.IWxUserinfoService;
import cn.tedu.util.PojoConvert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @author Kiven
 */
@RequestMapping("/wx/userinfo")
@RestController
@Api(tags = {"微信用户信息模块"})
public class WxUserinfoController {

    @Autowired
    private IWxUserinfoService wxUserinfoService;




    @GetMapping
    @ApiOperation(value = "动态查询userinfos,返回列表",notes="目前提供根据昵称,性别,城市查询")
    public JsonResult findWxUserinfoPage(WxUserinfoDTO wxUserinfoDTO, @NotNull Long pageCurrent, @NotNull Long size){
        PageInfo<WxUserinfoVo> list = wxUserinfoService.findWxUserinfos(wxUserinfoDTO,pageCurrent,size);
        return JsonResult.success(list);
    }



    /**
     *  接收请求 返回响应
     *  新增微信用户信息
     */
    @PostMapping
    @ApiOperation(value = "新增微信用户信息",notes = "新增微信用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wxUserinfoDTO",value = "用户信息",dataType = "WxUserinfoDTO")
    })
    public JsonResult addWxUserinfo(@Valid WxUserinfoDTO wxUserinfoDTO){
        // 复杂的业务逻辑 不要写在这儿
        wxUserinfoService.save(PojoConvert.convert(wxUserinfoDTO, WxUserinfo.class));
        return JsonResult.success();
    }


}
